package org.zn.etl.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.zn.datax.common.entity.ColumnInfo;
import org.zn.datax.common.entity.JobParamInfo;
import org.zn.datax.common.entity.TableInfo;
import org.zn.datax.param.ContextKey;
import org.zn.datax.param.JobConfigBuilder;
import org.zn.datax.param.JobParam;
import org.zn.etl.service.DataxService;

/**
 * 
 * @author zhounan 
 * @date 2024年5月17日
 * @version V1.0
 */
@Service
public class DataxServiceImpl implements DataxService {
	
	
	public JobParam getJobParam(String jobName) {
		
		JobParamInfo ji=new  JobParamInfo();
		ji.setSources(new String[]{"jdbc:oracle:thin:@172.16.4.217:1521:rsdb"});
	
		TableInfo table=new TableInfo();
		
		List<ColumnInfo> columns=new ArrayList<ColumnInfo>();
		ColumnInfo c1=new ColumnInfo();
		c1.setName("c1");
		c1.setType("varchar");
		
		ColumnInfo[] cs=new ColumnInfo[columns.size()];
		
		table.setColumns(columns.toArray(cs));
		table.setTable("Test");

		
		ji.setSourceTable(table);
		ji.setSourceType("oracle");
		
		ji.setTargetType("postgresql");
		ji.setTarget("jdbc:postgresql://172.16.204.121:5432/rsdb_reg");
		ji.setTargetTable(table);
		
		
		Map<String, Object> context=new HashMap<>();
		
		context.put(ContextKey.READER_UER, "rs_new");
		context.put(ContextKey.READER_PWD, "abcd_1234");
		
		context.put(ContextKey.WRITER_UER, "rsdb_reg");
		context.put(ContextKey.READER_PWD, "abcd_1234");
		
		JobParam jp=JobConfigBuilder.newBuilder(ji).addContextParam(context).build();
		
		return jp;
	
	}

}
